package com.xjrsoft.module.oa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjrsoft.module.oa.entity.XjrOaFileinfo;
import com.xjrsoft.module.oa.mapper.XjrOaFileinfoMapper;
import com.xjrsoft.module.oa.service.IXjrOafileinfoService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 文件表 服务实现类
 * </p>
 *
 * @author zwq
 * @since 2021-04-20
 */
@Service
public class XjrOafileinfoServiceImpl extends ServiceImpl<XjrOaFileinfoMapper, XjrOaFileinfo> implements IXjrOafileinfoService {

    @Autowired
    private XjrOaFileinfoMapper xjrOaFileinfoMapper;

  
    @Override
    public List<XjrOaFileinfo> query(String keywords, Integer fileType,Integer isRoot) {
        LambdaQueryWrapper<XjrOaFileinfo> fileinfoQueryWrapper = Wrappers.<XjrOaFileinfo>query().lambda().eq(XjrOaFileinfo::getDeleteMark, 0);
        if(!StringUtils.isEmpty(keywords)){
            fileinfoQueryWrapper.like(XjrOaFileinfo::getFileName, keywords);
        }
        if(isRoot==1){
            fileinfoQueryWrapper.eq(XjrOaFileinfo::getFolderId,"0");
        }
        if (fileType==0) {
            fileinfoQueryWrapper.eq(XjrOaFileinfo::getEnabledMark, 1);
        } else if (fileType==1||fileType==2) {
            //文档或图片
            fileinfoQueryWrapper.eq(XjrOaFileinfo::getFileExtensions, fileType.toString()).eq(XjrOaFileinfo::getEnabledMark, 1);
        } else if (fileType==3) {
            // 回收站里的文件
            fileinfoQueryWrapper.eq(XjrOaFileinfo::getEnabledMark, 0);
        } else if (fileType==4) {
            // 我的共享文件
            fileinfoQueryWrapper.eq(XjrOaFileinfo::getIsShare, 1).eq(XjrOaFileinfo::getEnabledMark, 1);
        } else if (fileType==5) {
            // 他人共享文件
            fileinfoQueryWrapper.eq(XjrOaFileinfo::getIsShare, 1).eq(XjrOaFileinfo::getEnabledMark, 1);
        }
      return this.list(fileinfoQueryWrapper);
    }


    //获取子文件
    @Override
    public List<XjrOaFileinfo> getSonFile(String folderId,Integer isEnabledMark) {
        LambdaQueryWrapper<XjrOaFileinfo> fileinfoQueryWrapper = Wrappers.<XjrOaFileinfo>query().lambda()
                .eq(XjrOaFileinfo::getDeleteMark, 0)
                .eq(XjrOaFileinfo::getEnabledMark,isEnabledMark)
                .eq(XjrOaFileinfo::getFolderId,folderId);
       return this.list(fileinfoQueryWrapper);
    }
}
